import React from 'react';

import {WeaUpload,WeaBrowser,WeaHelpfulTip,WeaDialog,WeaLocaleProvider,WeaTools, WeaSearchGroup, WeaFormItem,WeaInput,WeaNewScroll,WeaSelectGroup,WeaTable,WeaInputNumber,WeaColorPicker,WeaSelect,WeaCheckbox} from 'ecCom'
const getLabel = WeaLocaleProvider.getLabel;
import {WeaPortalShare,WeaMaterialLib} from 'weaPortalPublic';
import './style/';
import {Tabs, Button, Spin, Icon, message, Modal,Row,Col} from 'antd';
import {Carousel} from "./index";
const TabPane = Tabs.TabPane;
class Setting extends React.Component{



    load = (id)=>{
        WeaTools.callApi('/api/portal/E7form/saveInitE7form', 'POST', {"json":JSON.stringify({id:id,setting:JSON.stringify({})})}).then((result) => {
            if (result.status == true) {
                if(result.data != null){
                    let data = result.data
                    data.setting = JSON.parse(data.setting)
                    this.props.setStateData({data:data})
                }
            }
        });
    }

    cancelAndReflush = ()=>{
        const id = this.props.state.data.id
        this.props.setStateData({
            settingVisiable : false
        })


        this.load(id)
    }


    updateSetting = () =>{
        let data = JSON.parse(JSON.stringify(this.props.state.data))
        data.setting = JSON.stringify(data.setting)
        WeaTools.callApi('/api/portal/E7form/updateE7formById', 'POST', {"json":JSON.stringify(data)}).then((result) => {

            if (result.status == true) {
                this.props.setStateData({settingVisiable:false})
                message.success(getLabel(83551, '保存成功！'), 3);
            }else{
                message.error(getLabel(84544, '保存失败！'), 3);
            }
        });
    }


    setSetting = (temp)=>{
        const data = this.props.state.data
        const setting =Object.assign({},data.setting,temp)
        data.setting = setting
        this.props.setStateData({data:data})
    }

    render (){
        const {logoImage,bgImage} = this.props.state.data.setting
        let logoImageArr
        if (logoImage) {
           logoImageArr = logoImage.split(',').slice(0, 3);

        } else {
            logoImageArr = [
                '/wui/theme/ecology7/page/images/login/lg_bg1_wev8.jpg',
                '/wui/theme/ecology7/page/images/login/lg_bg2_wev8.jpg',
                '/wui/theme/ecology7/page/images/login/lg_bg3_wev8.jpg'
            ];

        }
        let bgImageSrc = '/wui/theme/ecology7/page/images/login/login_cbg_wev8.png';
        if (bgImage) {
            bgImageSrc = bgImage;
        }
        return (
            <WeaDialog
                title="设置"
                visible={this.props.state.settingVisiable}
                iconBgcolor='#1a57a0'
                hasScroll={false}
                style={{width: 900,height : 500}}
                onCancel={()=>{this.cancelAndReflush()}}
            >
                <Spin spinning={false}>
                    <Tabs defaultActiveKey="1" className="portal-esetting-tabs" onChange={()=>{}}>
                        <TabPane tab={getLabel(33368, '内容')} key="1">
                            <WeaSearchGroup title={getLabel(81711, '基本信息')} needTigger={true} showGroup={true} >
                                <div className="lr_managerSetting_style_base_div">
                                    <div style={{'margin-bottom':'10px'}}>
                                        <Row gutter={24} type="flex" justify="start" align="middle">
                                            <Col span={3}>背景图片 :</Col>
                                            <Col span={2}>
                                                <WeaMaterialLib multiCheck={false}  onChange={(value)=>{this.setSetting({bgImage:value})}} type='button' >
                                                     <Button type="primary">{getLabel(502488, '设置')}</Button>
                                                </WeaMaterialLib>
                                            </Col>
                                            <Col span={3}>
                                                {
                                                    bgImage ? (
                                                        <Button type="primary" onClick={()=>{this.setSetting({bgImage:""})}}>{getLabel(32757, '恢复默认')}</Button>
                                                    ):(
                                                        <Button >{getLabel(32757, '恢复默认')}</Button>
                                                    )
                                                }
                                            </Col>

                                        </Row>
                                        <div style={{'margin-top':'10px'}}>
                                            <img style={{width:'100px',height:'100px'}} src={bgImageSrc}/>
                                        </div>
                                    </div>
                                    <div style={{'margin-bottom':'10px'}}>
                                        <Row gutter={24} type="flex" justify="start" align="middle">
                                            <Col span={3}>滚动图片 :</Col>
                                            <Col span={2}>
                                                <WeaMaterialLib multiCheck={true}  onChange={(value)=>{this.setSetting({logoImage:value})}} type='button' >
                                                    <Button type="primary">{getLabel(502488, '设置')}</Button>
                                                </WeaMaterialLib>

                                            </Col>
                                            <Col span={3}>
                                                {
                                                    logoImage ? (
                                                        <Button type="primary" onClick={()=>{this.setSetting({logoImage:""})}}>{getLabel(32757, '恢复默认')}</Button>
                                                    ):(
                                                        <Button >{getLabel(32757, '恢复默认')}</Button>
                                                    )
                                                }

                                            </Col>

                                        </Row>
                                        <div style={{'margin-top':'10px'}}>
                                            {
                                                logoImageArr.map((item,index)=>{
                                                    return (
                                                          <img style={{width:'100px',height:'100px','margin-right':'5px'}} src={item}/>
                                                    )
                                                })
                                            }
                                        </div>
                                    </div>
                                </div>
                            </WeaSearchGroup>

                        </TabPane>
                    </Tabs>
                </Spin>
                <div className="portal-esetting-confirm lr_managerSetting_option_buttons_div" >
                    <Button type="primary" onClick={() => {this.updateSetting()}}>{getLabel(30986, '保存')}</Button>
                    <Button type="ghost"  style={{marginLeft: '10px'}} onClick={()=>{this.cancelAndReflush()}}>{getLabel(31129, '取消')}</Button>
                </div>
            </WeaDialog>
            )

    }

}
export default Setting